using System;
using System.Collections;

namespace Commons.Models.Settings.Matchers.Operators.Relational
{
	[Serializable]
	public class GreaterThanOperator<T> : IRelationalOperator<T>
	{
		public virtual OperatorType Type
		{
			get
			{
				return OperatorType.Gt;
			}
		}

		public virtual bool Operate(T v1, T v2)
		{
			if (v1 == null)
			{
				return false;
			}

			return GetMaxValue(v1) > GetMaxValue(v2);
		}

		protected double GetMaxValue(T v)
		{
			if (v is IEnumerable)
			{
				return GetMaxValue((IEnumerable) v);
			}
			else
			{
				return RelationalOperatorSupport.GetDouble(v);
			}
		}

		protected double GetMaxValue(IEnumerable list)
		{
			double maxValue = double.MinValue;
			foreach (object v in list)
			{
				maxValue = Math.Max(RelationalOperatorSupport.GetDouble(v), maxValue);
			}
			return maxValue;
		}
	}
}

